/**
 * 作者: wgx
 * 日期: 2025-04-21 11:14:06
 * 备注: 用户伤兵的恢复情况
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserSoldierRecover;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserSoldierRecoverModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 用户ID
    protected int soldierTotal; // 总的伤兵数量
    protected int type; // 恢复类型
    protected long startTime; // 开始时间
    protected long endTime; // 结束时间
    protected int recoverValue; // 每秒恢复的数量 (选择的模式+特权卡加成)
    protected long helpDbid; // 联盟互助的dbid
    protected int reduceTime; // 别人减少的时间
    protected String uniqeId = ""; // 唯一值id，每次治疗更新

    public void reset() {
    }

    protected String getKey() {
        return "UserSoldierRecover." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_soldier_recover"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 用户ID
        obj.put("soldierTotal", soldierTotal); // 总的伤兵数量
        obj.put("type", type); // 恢复类型
        obj.put("startTime", startTime); // 开始时间
        obj.put("endTime", endTime); // 结束时间
        obj.put("recoverValue", recoverValue); // 每秒恢复的数量 (选择的模式+特权卡加成)
        obj.put("helpDbid", helpDbid); // 联盟互助的dbid
        obj.put("reduceTime", reduceTime); // 别人减少的时间
        obj.put("uniqeId", uniqeId); // 唯一值id，每次治疗更新
        return obj;
    }

    public PBUserSoldierRecover.Builder takeInitBuilder() {
        PBUserSoldierRecover.Builder sb = PBUserSoldierRecover.newBuilder();
        if (soldierTotal != 0) {
            sb.setSoldierTotal(soldierTotal);
        }
        if (type != 0) {
            sb.setType(type);
        }
        if (startTime != 0) {
            sb.setStartTime(startTime);
        }
        if (endTime != 0) {
            sb.setEndTime(endTime);
        }
        if (recoverValue != 0) {
            sb.setRecoverValue(recoverValue);
        }
        if (reduceTime != 0) {
            sb.setReduceTime(reduceTime);
        }
        if (!uniqeId.isEmpty()) {
            sb.setUniqeId(uniqeId);
        }
        return sb;
    }

    public PBUserSoldierRecover.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserSoldierRecover.Builder sb = PBUserSoldierRecover.newBuilder();
        if (isFieldUpdate("soldierTotal")) {
            sb.setSoldierTotal(soldierTotal);
        }
        if (isFieldUpdate("type")) {
            sb.setType(type);
        }
        if (isFieldUpdate("startTime")) {
            sb.setStartTime(startTime);
        }
        if (isFieldUpdate("endTime")) {
            sb.setEndTime(endTime);
        }
        if (isFieldUpdate("recoverValue")) {
            sb.setRecoverValue(recoverValue);
        }
        if (isFieldUpdate("reduceTime")) {
            sb.setReduceTime(reduceTime);
        }
        if (isFieldUpdate("uniqeId")) {
            sb.setUniqeId(uniqeId);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public int getSoldierTotal() {
        return soldierTotal;
    }

    public void putSoldierTotal(int soldierTotal) {
        if (this.soldierTotal != soldierTotal) {
            this.soldierTotal = soldierTotal;
            updateRedisHashField(getKey(), "soldierTotal", this.soldierTotal);
        }
    }

    public void addSoldierTotal(int value) {
        this.soldierTotal += value;
        updateRedisHashField(getKey(), "soldierTotal", this.soldierTotal);
    }

    public int getType() {
        return type;
    }

    public void putType(int type) {
        if (this.type != type) {
            this.type = type;
            updateRedisHashField(getKey(), "type", this.type);
        }
    }

    public void addType(int value) {
        this.type += value;
        updateRedisHashField(getKey(), "type", this.type);
    }

    public long getStartTime() {
        return startTime;
    }

    public void putStartTime(long startTime) {
        if (this.startTime != startTime) {
            this.startTime = startTime;
            updateRedisHashField(getKey(), "startTime", this.startTime);
        }
    }

    public void addStartTime(long value) {
        this.startTime += value;
        updateRedisHashField(getKey(), "startTime", this.startTime);
    }

    public long getEndTime() {
        return endTime;
    }

    public void putEndTime(long endTime) {
        if (this.endTime != endTime) {
            this.endTime = endTime;
            updateRedisHashField(getKey(), "endTime", this.endTime);
        }
    }

    public void addEndTime(long value) {
        this.endTime += value;
        updateRedisHashField(getKey(), "endTime", this.endTime);
    }

    public int getRecoverValue() {
        return recoverValue;
    }

    public void putRecoverValue(int recoverValue) {
        if (this.recoverValue != recoverValue) {
            this.recoverValue = recoverValue;
            updateRedisHashField(getKey(), "recoverValue", this.recoverValue);
        }
    }

    public void addRecoverValue(int value) {
        this.recoverValue += value;
        updateRedisHashField(getKey(), "recoverValue", this.recoverValue);
    }

    public long getHelpDbid() {
        return helpDbid;
    }

    public void putHelpDbid(long helpDbid) {
        if (this.helpDbid != helpDbid) {
            this.helpDbid = helpDbid;
            updateRedisHashField(getKey(), "helpDbid", this.helpDbid);
        }
    }

    public void addHelpDbid(long value) {
        this.helpDbid += value;
        updateRedisHashField(getKey(), "helpDbid", this.helpDbid);
    }

    public int getReduceTime() {
        return reduceTime;
    }

    public void putReduceTime(int reduceTime) {
        if (this.reduceTime != reduceTime) {
            this.reduceTime = reduceTime;
            updateRedisHashField(getKey(), "reduceTime", this.reduceTime);
        }
    }

    public void addReduceTime(int value) {
        this.reduceTime += value;
        updateRedisHashField(getKey(), "reduceTime", this.reduceTime);
    }

    public String getUniqeId() {
        return uniqeId;
    }

    public void putUniqeId(String uniqeId) {
        if (!this.uniqeId.equals(uniqeId)) {
            this.uniqeId = uniqeId;
            updateRedisHashField(getKey(), "uniqeId", this.uniqeId);
        }
    }

}